package com.gz.springcloud.controller;

import com.gz.springcloud.entity.Member;
import com.gz.springcloud.entity.Result;
import com.gz.springcloud.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
public class MemberController {

    @Resource
    private MemberService memberService;

    @PostMapping("/member/save")
    public Result save(@RequestBody Member member) {
        int affected = memberService.save(member);
        if (affected>0) {
            return Result.success("添加会员成功 member-service-provider-10001", affected);
        }else {
            return Result.error("401","添加会员失败 member-service-provider-10001");
        }
    }

    @GetMapping("/member/get/{id}")
    public Result getMemberById(@PathVariable("id") Long id) {
        Member member = memberService.queryMemberById(id);
        if (member!=null) {
            return Result.success("查询成功 member-service-provider-10001",member);
        }else {
            return Result.error("402","查询的id不存在 member-service-provider-10001");
        }
    }
}
